#include <nice2d/components/selectable.h>

class SelectableData
{
public:
    bool selected = false;
};

Selectable::Selectable(NodePointer object):
    Component(object)
{
    data = std::make_unique<SelectableData>();
}

Selectable::~Selectable()
{
}

void Selectable::select()
{
    if(!data->selected)
    {
        data->selected = true;
        selected(shared_from_this());
    }
}

void Selectable::toggleSelected()
{
    if(data->selected)
        unselect();
    else
        select();
}

void Selectable::unselect()
{
    if(data->selected)
    {
        data->selected = false;
        unselected(shared_from_this());
    }
}

bool Selectable::isSelected() const
{
    return data->selected;
}
